package com.apts.servise;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.apts.jfinalbase.BaseJsonPojo;
import com.apts.jfinalbase.BaseServise;
import com.apts.model.TbEnterprise;
import com.apts.pojo.NomalPojo;

public class EnterpriseEditServise extends BaseServise {
	public static final EnterpriseEditServise Service = new EnterpriseEditServise();

	// 查找所有企业信息
	public BaseJsonPojo findAll() {
		List<TbEnterprise> list = TbEnterprise.dao.findAll();
		List<Map<String, Object>> TbEnterpriseSet = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>(0);
			TbEnterprise enterprise = list.get(i);
			map.put("id", enterprise.get("id"));
			map.put("epname" + i, enterprise.get("epname"));
			map.put("regcode" + i, enterprise.get("regcode"));
			map.put("address" + i, enterprise.get("address"));
			map.put("runscope" + i, enterprise.get("runscope"));
			map.put("mobiletele" + i, enterprise.get("mobiletele"));
			map.put("cellphone" + i, enterprise.get("cellphone"));
			map.put("isdeleted" + i, enterprise.get("isdeleted"));
			map.put("regtime", enterprise.get("regtime"));
			map.put("legalperson" + i, enterprise.get("legalperson"));
			map.put("intruduction" + i, enterprise.get("intruduction"));
			map.put("logo", enterprise.get("logo"));
			TbEnterpriseSet.add(map);
		}
		Map<String, Object> map2 = new HashMap<String, Object>(0);
		map2.put("count", list.size());
		map2.put("list", list);
		return new NomalPojo(map2);
	}

	// 根据企业id精确查找(精确查找才会具体显示企业的介绍)(以及logo)
	public BaseJsonPojo findById(String id) {
		TbEnterprise enterprise = TbEnterprise.dao.findById(id);
		Map<String, Object> map = new HashMap<String, Object>(0);
		map.put("id", enterprise.get("id"));//企业id
		map.put("epname", enterprise.get("epname"));// 企业名
		map.put("regcode", enterprise.get("regcode"));// 注册号
		map.put("address", enterprise.get("address"));// 地址
		map.put("runscope", enterprise.get("runscope"));// 经营范围
		map.put("mobiletele", enterprise.get("mobiletele"));// 移动电话
		map.put("cellphone", enterprise.get("cellphone"));// 固定电话
		map.put("isdeleted", enterprise.get("isdeleted"));// 企业是否失效
		map.put("regtime", enterprise.get("regtime"));// 注册时间
		map.put("legalperson", enterprise.get("legalperson"));// 企业法人
		map.put("intruduction", enterprise.get("intruduction"));// 企业介绍
		map.put("logo", enterprise.get("logo"));// logo图片地址

		return new NomalPojo(map);

	}

	// 根据企业编号精确查找
	public BaseJsonPojo findByRegcode(String regcode) {
		List<TbEnterprise> list = TbEnterprise.dao.findbyregcode(regcode);
		List<Map<String, Object>> TbEnterpriseSet = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>(0);
			TbEnterprise enterprise = list.get(i);
			map.put("id", enterprise.get("id"));
			map.put("epname" + i, enterprise.get("epname"));
			map.put("regcode" + i, enterprise.get("regcode"));
			map.put("address" + i, enterprise.get("address"));
			map.put("runscope" + i, enterprise.get("runscope"));
			map.put("mobiletele" + i, enterprise.get("mobiletele"));
			map.put("cellphone" + i, enterprise.get("cellphone"));
			map.put("isdeleted" + i, enterprise.get("isdeleted"));
			map.put("regtime", enterprise.get("regtime"));
			map.put("legalperson" + i, enterprise.get("legalperson"));
			map.put("intruduction" + i, enterprise.get("intruduction"));
			map.put("logo", enterprise.get("logo"));
			TbEnterpriseSet.add(map);
		}
		Map<String, Object> map2 = new HashMap<String, Object>(0);
		map2.put("count", list.size());
		map2.put("list", list);
		return new NomalPojo(map2);

	}

	// 根据企业名模糊查找
	public BaseJsonPojo findByName(String epname) {
		List<TbEnterprise> list = TbEnterprise.dao.findbyname(epname);
		List<Map<String, Object>> TbEnterpriseSet = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>(0);
			TbEnterprise enterprise = list.get(i);
			map.put("id", enterprise.get("id"));
			map.put("epname" + i, enterprise.get("epname"));
			map.put("regcode" + i, enterprise.get("regcode"));
			map.put("address" + i, enterprise.get("address"));
			map.put("runscope" + i, enterprise.get("runscope"));
			map.put("mobiletele" + i, enterprise.get("mobiletele"));
			map.put("cellphone" + i, enterprise.get("cellphone"));
			map.put("isdeleted" + i, enterprise.get("isdeleted"));
			map.put("regtime", enterprise.get("regtime"));
			map.put("legalperson" + i, enterprise.get("legalperson"));
			map.put("intruduction" + i, enterprise.get("intruduction"));
			map.put("logo", enterprise.get("logo"));
			TbEnterpriseSet.add(map);
		}
		Map<String, Object> map2 = new HashMap<String, Object>(0);
		map2.put("count", list.size());
		map2.put("list", list);
		return new NomalPojo(map2);
	}

	// 根据企业地址模糊查找
	public BaseJsonPojo findByAddress(String address) {
		List<TbEnterprise> list = TbEnterprise.dao.findbyaddress(address);
		List<Map<String, Object>> TbEnterpriseSet = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>(0);
			TbEnterprise enterprise = list.get(i);
			map.put("id", enterprise.get("id"));
			map.put("epname" + i, enterprise.get("epname"));
			map.put("regcode" + i, enterprise.get("regcode"));
			map.put("address" + i, enterprise.get("address"));
			map.put("runscope" + i, enterprise.get("runscope"));
			map.put("mobiletele" + i, enterprise.get("mobiletele"));
			map.put("cellphone" + i, enterprise.get("cellphone"));
			map.put("isdeleted" + i, enterprise.get("isdeleted"));
			map.put("regtime", enterprise.get("regtime"));
			map.put("legalperson" + i, enterprise.get("legalperson"));
			map.put("intruduction" + i, enterprise.get("intruduction"));
			map.put("logo", enterprise.get("logo"));
			TbEnterpriseSet.add(map);
		}
		Map<String, Object> map2 = new HashMap<String, Object>(0);
		map2.put("count", list.size());
		map2.put("list", list);
		return new NomalPojo(map2);
	}

	// 根据企业经营范围模糊查找
	public BaseJsonPojo findByRunscope(String runscope) {
		List<TbEnterprise> list = TbEnterprise.dao.findbyrunscope(runscope);
		List<Map<String, Object>> TbEnterpriseSet = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>(0);
			TbEnterprise enterprise = list.get(i);
			map.put("id", enterprise.get("id"));
			map.put("epname" + i, enterprise.get("epname"));
			map.put("regcode" + i, enterprise.get("regcode"));
			map.put("address" + i, enterprise.get("address"));
			map.put("runscope" + i, enterprise.get("runscope"));
			map.put("mobiletele" + i, enterprise.get("mobiletele"));
			map.put("cellphone" + i, enterprise.get("cellphone"));
			map.put("isdeleted" + i, enterprise.get("isdeleted"));
			map.put("regtime", enterprise.get("regtime"));
			map.put("legalperson" + i, enterprise.get("legalperson"));
			map.put("intruduction" + i, enterprise.get("intruduction"));
			map.put("logo", enterprise.get("logo"));
			TbEnterpriseSet.add(map);
		}
		Map<String, Object> map2 = new HashMap<String, Object>(0);
		map2.put("count", list.size());
		map2.put("list", list);
		return new NomalPojo(map2);
	}

	// 根据企业法定代表人模糊查找
	public BaseJsonPojo findByLegalperson(String legalperson) {
		List<TbEnterprise> list = TbEnterprise.dao.findbylegalperson(legalperson);
		List<Map<String, Object>> TbEnterpriseSet = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>(0);
			TbEnterprise enterprise = list.get(i);
			map.put("id", enterprise.get("id"));
			map.put("epname" + i, enterprise.get("epname"));
			map.put("regcode" + i, enterprise.get("regcode"));
			map.put("address" + i, enterprise.get("address"));
			map.put("runscope" + i, enterprise.get("runscope"));
			map.put("mobiletele" + i, enterprise.get("mobiletele"));
			map.put("cellphone" + i, enterprise.get("cellphone"));
			map.put("isdeleted" + i, enterprise.get("isdeleted"));
			map.put("regtime", enterprise.get("regtime"));
			map.put("legalperson" + i, enterprise.get("legalperson"));
			map.put("intruduction" + i, enterprise.get("intruduction"));
			map.put("logo", enterprise.get("logo"));
			TbEnterpriseSet.add(map);
		}
		Map<String, Object> map2 = new HashMap<String, Object>(0);
		map2.put("count", list.size());
		map2.put("list", list);
		return new NomalPojo(map2);
	}

	// 添加企业信息
	public void Add(Map<String, Object> map) {
		TbEnterprise.dao.insert(map);
	}

	// 跟新企业信息
	public void Update(Map<String, Object> map) {
		TbEnterprise.dao.update(map);
	}

	// 删除企业信息（注销企业信息）
	public void Delete(String id) {
		TbEnterprise.dao.Delete(id);
	}

}
